
local slk = require 'jass.slk'




class.actor = extends(class.model2){

    default_size = 1,

    size = 1,

    name = '',

    w = 32,

    h = 32,

    level = 1,

    init = function (self)
        local file = get_unit_slk(self.name, 'File') or '' 
        if file:len() > 0 then 
            local path = file
            local ext = path:sub(-4):lower()
            if ext ~= '.mdl' and ext ~= '.mdx' then 
                path = path .. '.mdx'
            end 
            self.model = path
        else 
            self.model = ''
        end 
    

        class.model2.init(self)

        self:set_level(self.level)
        self:set_actor(self.name)

        return self
    end,

    new = function (parent,name,x,y,w,h)
        local model = class.actor:builder 
        {
            parent = parent,
            name = name,
            x = x,
            y = y,
            w = w or 32,
            h = h or 32,
        }
        return model
    end,

    reset_size = function (self)
        self:set_size(class.actor.default_size)
    end,

    set_actor = function (self,name)
        
        if name == '' then 
            self:hide()
            return 
        end 
     
        self:set_name(name)
    
        --local path = get_unit_slk(name, 'File') or ''
        local path = get_unit_slk(name, 'File') or ''
        local ext = path:sub(-4):lower()
        if ext ~= '.mdl' and ext ~= '.mdx' then 
            path = path .. '.mdx'
        end 
        self:set_model(".mdx", 0)
        self:set_model(path, ac.player.self:get_id() - 1)
        self:set_size(1)

        self:set_object_point({0, 0, -120})
        self:set_camera_source({250, 0, 100})
        self:set_camera_target({0, 0, 0})
        
        self:set_animation_by_index(1,true)
        
        self:show()

    end,

    get_name = function (self)
        return self.name or ''
    end,

    set_name = function (self,name)
        self.name = name 
    end,
  
    set_level = function (self,level)
        self.level = level 
    end,

    get_level = function (self)
        if not self.unit then 
            return 0 
        end
        return self.level or 1
    end,

    get_level_tip = function (self)
        if self.name == '未开放' then 
            return ''
        end 
        local s = {'星级 ','|cffffff00'}
        for i = 1, self:get_level() do 
            s[#s + 1] = '★'
        end 
        s[#s + 1] = '|r'
        return table.concat(s)
    end,

    level_color_map = {
        'ffffff',
        '00bdec',
        'df19d0',
        'ffff00',
        'FF7F50',
    },

    get_title = function (self)
        if self.name == '未开放' then 
            return self.name 
        end 
  
        return self:get_name()
    end,

    get_rank_tip = function (self)
        if not self.unit or not self.unit.rank then 
            return 'N'
        end
        return self.unit.rank
    end,

    
}
